import {useIntersectionObserver} from "@vueuse/core";

export default {
    //图片懒加载：在用户无法看到图片时，不加载图片
    mounted(el) {
        //1.获取src图片路径
        const imgSrc = el.src
        //2.把src图片置为空
        el.src = ''
        //3.用户可见 再加载图片
        const {stop} = useIntersectionObserver(el, ([{isIntersecting}]) => {
            if (isIntersecting) {
                el.src = imgSrc
                //停止监听
                stop()
            }
        })
    }
}
